<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Members;
use App\Models\Members\Member;
use App\Models\Orders\PayOrder;
use App\Models\Rooms\RoomsGoods;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class IndexController extends Controller
{
    //首页数据
    public function index()
    {
        //累计注册数量
        $memberCount = Member::count();

        //昨日注册数量
        $yestodayMemberCount = Member::whereIn('created_at',[now()->subDays(1)->toDateString(),now()->toDateString()])->count();

        //当日注册人数
        $todayMemberCount = Member::whereIn('created_at',[now()->toDateString(),now()->addDays(1)->toDateString()])->count();

        //累计充值金额
        $totalMoney = PayOrder::where('status',1)->sum('order_price');

        //昨日充值金额
        $yesTodaytotalMoney = PayOrder::where('status',1)->whereIn('created_at',[now()->subDays(1)->toDateString(),now()->toDateString()])->sum('order_price');

        //当日充值金额
        $toDayTotalMoney = PayOrder::where('status',1)->whereIn('created_at',[now()->toDateString(),now()->addDays(1)->toDateString()])->sum('order_price');

        //累计开奖金额
        $totalRoomGoodsPrice = RoomsGoods::where('status',2)->sum('goods_bean') / 10;

        $todayTotalRoomGoodsPrice = RoomsGoods::where('status',2)->whereIn('created_at',[now()->toDateString(),now()->addDays(1)->toDateString()])->sum('goods_bean') / 10;

        $yestodayTotalRoomGoodsPrice = RoomsGoods::where('status',2)->whereIn('created_at',[now()->subDays(1)->toDateString(),now()->toDateString()])->sum('goods_bean') / 10;
        //当前金豆余额总额
        $totalBean = Members::sum('bean');
        $data = [
            ['title' => '累计注册', 'icon' => 'md-person-add', 'count' => floatval($memberCount), 'color' => '#ed4014'],
            ['title' => '昨日注册', 'icon' => 'md-person-add', 'count' => floatval($yestodayMemberCount), 'color' => '#2d8cf0'],
            ['title' => '今日注册', 'icon' => 'md-person-add', 'count' => floatval($todayMemberCount), 'color' => '#19be6b'],
            ['title' => '累计充值', 'icon' => 'logo-usd', 'count' => floatval($totalMoney), 'color' => '#ed4014'],
            ['title' => '昨日充值', 'icon' => 'logo-usd', 'count' => floatval($yesTodaytotalMoney), 'color' => '#2d8cf0'],
            ['title' => '今日充值', 'icon' => 'logo-usd', 'count' => floatval($toDayTotalMoney), 'color' => '#19be6b'],
            ['title' => '累计开奖', 'icon' => 'md-home', 'count' => floatval($totalRoomGoodsPrice), 'color' => '#ed4014'],
            ['title' => '昨日开奖', 'icon' => 'md-home', 'count' => floatval($yestodayTotalRoomGoodsPrice), 'color' =>'#2d8cf0'],
            ['title' => '今日开奖', 'icon' => 'md-home', 'count' => floatval($todayTotalRoomGoodsPrice), 'color' => '#19be6b'],
            ['title' => '金豆剩余', 'icon' => 'md-home', 'count' => floatval($totalBean), 'color' => '#19be6b'],
        ];
        return $this->success($data);
    }
}
